﻿// <copyright file="DialogLauncherWindow.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    public enum DialogType
    {
        Open,
        Save
    }

    public partial class DialogLauncherWindow : ChildWindow
    {
        public DialogLauncherWindow()
        {
            InitializeComponent();
        }

        public DialogType DialogType { get; set; }
        public string DialogFilter { get; set; }
        public FileStream SelectedFile { get; set; }

        private void BrowseButton_Click(object sender, RoutedEventArgs e)
        {
            if (DialogType == DialogType.Open)
            {
                ShowOpenFileDialog();
            }
            else
            {
                ShowSaveFileDialog();
            }
        }

        private void ShowOpenFileDialog()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = this.DialogFilter;

            if (openFileDialog.ShowDialog() == true)
            {
                this.FileTextBox.Text = openFileDialog.File.Name;
                this.FileTextBox.IsReadOnly = true;

                this.SelectedFile = openFileDialog.File.OpenRead();
            }
        }

        private void ShowSaveFileDialog()
        {
            throw new NotImplementedException();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

